package demo;

import demo.utils.SimpleCommentGenerator;
import demo.utils.WriteCallBack;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class CustomerGenerator {
    public static void main(String[] args) {
        try {
            List<String> warnings = new ArrayList<String>();
            boolean overwrite = true;
            ClassLoader classloader = Thread.currentThread().getContextClassLoader();
            //获得配置文件流
            InputStream is = classloader.getResourceAsStream("generatorConfig.xml");
            //创建一个配置文件解析器
            ConfigurationParser cp = new ConfigurationParser(warnings);
            //将配置文件解析成Configuration对象
            Configuration config = cp.parseConfiguration(is);
            //设置文件处理，是否覆盖
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            //创建MybatisGenerator对象
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
            //执行生成代码程序
            myBatisGenerator.generate(new WriteCallBack());
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
